<?php
/**
 * Author: Administrator
 * Date: 2022/7/23 2:05
 */

namespace DesignPatterns\Behavioral\State;


class OrderModel
{
    public $state;
    public $id;

    public function __construct($id=null)
    {
        if ($id) {
            $this->id = $id;
            $this->state = $id < 5 ? 'complete' : ($id > 20 ? 'created' : 'shipping');
        }
    }

    public function updateState($state) {
        $this->state = $state;
        echo 'updated'.PHP_EOL;
    }

    public function save() {
        $this->id = \random_int(1, 10);
        $this->state = 'created';
        echo 'created'.PHP_EOL;
    }

}